package com.smsc.headend.connector.builder;

import com.smsc.headend.connector.builder.impl.DefaultAssociationBuilder;
import com.smsc.headend.connector.builder.impl.HLSAssociationBuilder;
import com.smsc.headend.connector.builder.impl.LLSAssociationBuilder;
import com.smsc.headend.module.asset.entity.ComEntity;
import com.smsc.headend.module.asset.entity.Meter;
import com.smsc.headend.module.asset.enums.SecurityLevel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.config.AutowireCapableBeanFactory;
import org.springframework.stereotype.Component;

/**
 * @author liangli
 * @date 2020/8/30
 */
@Component
public class AssociationBuilderFactory {
    @Autowired
    AutowireCapableBeanFactory autowireCapableBeanFactory;

    /**
     * @param securityLevel {@link SecurityLevel}
     * @param comEntity
     * @param meter
     * @return
     */
    public AssociationBuilder getBuilder(Integer securityLevel, ComEntity comEntity, Meter meter) {
        // Long modelId = deviceService.getModelId(com, meter);
        AssociationBuilder builder = null;
        SecurityLevel level = SecurityLevel.parse(securityLevel);
        switch (level) {
            case HLS:
//                if (modelId == 3001 || modelId == 3003) {      //虚拟表测试 用default aa  builder。  打包正式环境需要注释掉
//                    builder = new DefaultAssociationBuilder();
//                } else {
                builder = new HLSAssociationBuilder();
//                }
                break;
            case LLS:
                if(meter != null) {
                    builder = new LLSAssociationBuilder();
                } else {
                    builder = new DefaultAssociationBuilder();
                }
                break;
            default:
                builder = new DefaultAssociationBuilder();
        }
        autowireCapableBeanFactory.autowireBean(builder);
        return builder;
    }
}
